package routerServer

import (
	"gitee.com/fierce_wolf/go-fox-edge-common/commRedis"
)

type ITopicHandler interface {
	Subscribe(message string)
}

type topicHandler struct {
	handler ITopicHandler
}

func (e *topicHandler) subscribe() {
	pubsub := commRedis.Client.Subscribe("topic_gateway_request")
	defer pubsub.Close()

	ch := pubsub.Channel()
	for msg := range ch {
		if e.handler == nil {
			continue
		}

		// 接收路由请求，并保存配置到redis
		e.handler.Subscribe(msg.Payload)

		// 根据redis配置，重新注册路由
		router.registerRouter()
	}
}
